<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="../../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!doctype html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta charset="utf-8">
    <link rel="stylesheet" href="${ctx}/css/sapar.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common.css"/>
    <script type="text/javascript" src="${ctx}/js/jquery.js"></script>
    <script type="text/javascript" src="${ctx}/js/sapar.js"></script>
    <script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
    <script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
    <link href="${ctx}/css/select2.min.css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css"/>
    <script type="text/javascript" src="${ctx}/js/mask.js"></script>
    <title>库存信息</title>
    <style type="text/css">
        #left {
            float: left;
            width: 100%;
        }

        #saper-container {
            float: left;
            width: 100%;
            background: url(${ctx}/images/dian.png) repeat-y 69% 0;
        }

        #table_left {
            float: left;
            width: 68%;
            min-height: 300px
        }

        #right {
            float: right;
            width: 30%;
            min-height: 300px
        }

        .search-box .iselect-wrapper {
            float: left;
            margin-right: 5px;
            width: 150px;
        }

        .search-box .iselect-wrapper .iselect {
            width: 150px;
        }

        .fafang {
            margin-left: 10px;
        }

        #weifa {
            color: red;
            font-weight: bolder;
        }

        #yifa {
            color: green;
            font-weight: bold;
        }

        .s1 {
            color: #0033FF;
            font-weight: 900;
            font-size: 13px;
        }

        th {
            text-align: center;
        }

        td {
            text-align: center;
        }

        .fafangkeshi {
            float: left;
            margin-left: 50px;
        }

        #ff {
            float: left;
        }

        .search_text {
            width: 130px;
            height: 27px;
        }

        #fafangren {
            width: 100px;
            height: 27px;
        }

        #baolx {
            width: 100px;
        }
    </style>
</head>
<body>
<div id="mask" class="mask"></div>
<div id="left">
    <audio src="../../../audio/Beep_Short.mp3" id="audio"></audio><!-- 成功提示音 -->
    <audio src="../../../audio/Alarm_Clock (1).mp3" id="audio1"></audio>
    <div id="saper-container">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>库存信息</h2>
            </div>
            <div class="subfiled-content">
                <div class="search-box clearfix">
                    <%--<div class="kv-item clearfix">--%>
                    <%--<label>选择包类型：</label>--%>
                    <%--<div class="kv-item-content" id="aaa">--%>
                    <%--<select id="baolx" class="">--%>
                    <%--<c:if test="${packageMuban.packageId != null }">--%>
                    <%--<option value="${packageMuban.packageId }">${packageMuban.packageName }</option>--%>
                    <%--<option value="">请选择</option>--%>
                    <%--</c:if>--%>
                    <%--<c:if test="${packageMuban.packageId == null }">--%>
                    <%--<option value="">请选择</option>--%>
                    <%--</c:if>--%>
                    <%--<c:if test="${mubans != null}">--%>
                    <%--<c:forEach items="${mubans}" var="pro">--%>
                    <%--<c:if test="${pro.packageId != packageMuban.packageId }">--%>
                    <%--<option value="${pro.packageId}" >${pro.packageName}</option>--%>
                    <%--</c:if>	--%>
                    <%--</c:forEach>		                                --%>
                    <%--</c:if>			                                --%>
                    <%--</select>--%>
                    <%--</div>--%>
                    <%--</div>--%>
                    <%--<a href="javascript:;" class="sapar-btn sapar-btn-recom query-btn" id="chaxun">查询</a>--%>
                    <div class="kv-item clearfix">

                        <label>包条码:</label>
                        <div class="kv-item-content">
                            <input type="text" name="packageTiaoma" placeholder="发放包条码"
                                   class="ffr" id="packageTiaoma">
                        </div>

                    </div>
                    <div class="fafangkeshi">
                        <label>发放人：</label>
                        <input type="text" id="fafangren" name="fafangren" placeholder="发放人条码"
                               >

                        <label>发放科室：</label>
                        <select class="search_text" id="keshi">
                            <option value="">请选择</option>
                            <c:if test="${alldeparts != null}">
                                <c:forEach items="${alldeparts}" var="pro">
                                    <c:if test="${pro.departmentId!=15 }">
                                        <option value="${pro.departmentId}">${pro.departmentName}</option>
                                    </c:if>
                                </c:forEach>
                            </c:if>
                        </select>

                    </div>
                    <div id="ff"><a href="javascript:;" class="sapar-btn sapar-btn-recom query-btn" id="zhihuan">发放</a>
                    </div>
                </div>
                <!--表格开始-->


                <div id="table_left" class="table">
                    <!--表格操作-->
                    <!-- <div class="table-operate ue-clear">
                         <a href="javascript:;" class="add" id="add">增加</a>
						 <a href="javascript:;" class="edit">修改</a>
						  <a href="javascript:;" class="del" id="shanchuzhubiao">删除</a>
                    </div> -->
                    <!--表格具体内容-->
                    <div class="table-box">
                        <table>
                            <thead>
                            <tr>
                                <th><input type="checkbox" id="checkall" name="checkall"/></th>
                                <th class="text-left">包条码</th>
                                <th class="text-left">包名</th>
                                <!-- <th class="text-left">所属科室</th> -->
                                <th class="text-left">包装类型</th>
                                <th class="text-left">有效期(天)</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:if test="${kucunbaoList == null || kucunbaoList == '' }">
                                <tr class="no-data product">
                                    <td colspan="10" style="color: red">暂时没有数据</td>
                                </tr>
                            </c:if>

                            <%--
                                <c:if test="${kucunbaoList == null || kucunbaoList == ''}">
                                    <tr class="no-data product"><td colspan="10" style="color: red">暂时没有数据</td></tr>
                                </c:if> --%>
                            <c:if test="${kucunbaoList != null && kucunbaoList != ''}">
                                <c:forEach items="${kucunbaoList}" var="kucun">
                                    <tr class="xiangxi" data="${kucun.packageTiaoma}">
                                        <td><input type="checkbox" name="key" value="${kucun.packageTiaoma}"/></td>
                                            <%-- <td><input type="checkbox" name="key" value="${kucun.packageTiaoma}" data2="${shoushubao.fafangLiushui}"/></td> --%>
                                        <td>${kucun.packageTiaoma}</td>
                                        <td>${kucun.tbPackageMuban.packageName}</td>
                                            <%-- <td>
                                                <c:if test="${kucun.tbPackageMuban.packageDepartid != null }">${kucun.tbPackageMuban.tbDepartment.departmentName}</c:if>
                                            </td> --%>
                                        <td>${kucun.tbPackageMuban.zsDabao.dabaoName}</td>
                                        <td>${kucun.tbPackageMuban.zsDabao.dabaoYouxiaoqiDays}</td>
                                            <%-- <td>${kucun.packageMiejunFangshi}</td>
                                            <td><fmt:formatDate value="${kucun.packageCreatetime}" type="date" pattern="yyyy-MM-dd HH:mm:ss"/></td> --%>
                                    </tr>
                                </c:forEach>
                            </c:if>
                            </tbody>
                        </table>
                    </div>
                    <div id="saper-ft">
                        <div id="kkpager"></div>
                    </div>

                </div><!--表格结束-->

                <div id="right">
                    <!--表格开始-->
                    <div class="table">
                        <div class="table-box">
                            <!-- <div class="table-operate ue-clear">
                            </div> -->
                            <table id="detail">
                                <thead>
                                <tr>
                                    <th>包分类</th>
                                    <th>包数量</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:if test="${kuncunnum != null }">
                                    <c:forEach items="${kuncunnum }" var="kucun">
                                        <tr class='packMx' data="${kucun.baoid }">
                                            <td>${kucun.name }</td>
                                            <td>${kucun.num }</td>
                                        </tr>
                                    </c:forEach>
                                </c:if>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/js/select2.js" type="text/javascript"></script>
<script src="/js/pinyin.js" type="text/javascript"></script>
<script type="text/javascript">


    $(function () {
        var baoleixing = $("#baolx").val();
        //定义一个全局变量
        var g_packageId = "";
        /* var totalPage =
        ${total};
         var pageNo = getParameter('pageIndex');
         if(!pageNo){
         pageNo = 1;
         }
         //生成分页
         //有些参数是可选的，比如lang，若不传有默认值
         kkpager.generPageHtml({
         pno : pageNo,
         //总页码
         total : totalPage,
         //链接前部
         hrefFormer : '
        ${ctx}/wupingfafang/kucunxinxi',
         //链接尾部
         hrefLatter : '.do',
         getLink : function(n){
         return this.hrefFormer + this.hrefLatter + "?pageIndex="+n+"&searchTxt="+$(".search_text").val()+"&id="+baoleixing;
         }
         }); */

        $('select').select2();

        $("#checkall").click(function () {
            if (this.checked) {
                $("input[name='key']").attr('checked', true)
            } else {
                $("input[name='key']").attr('checked', false)
            }
        });

        $("#chaxun").click(function () {
            baoleixing = $("#baolx").val();
            window.location.href = "${ctx}/wupingfafang/baolxchaxun.do?id=" + baoleixing;
        });

        $("#zhihuan").click(function () {
            var btn = true;
            var tiaoma = getSelRecord();
            var keshi = $("#keshi").val();
            var fafangren = $("#fafangren").val();
            if (tiaoma.length == 0) {
                alert("请选择要发放的包");
                btn = false;
                return btn;
            }
            if (isNullOrEmpty(keshi)) {
                alert("请选择置换科室");
                btn = false;
                return btn;
            }

            if (isNullOrEmpty(fafangren)) {
                alert("请输入发放人条码");
                btn = false;
                return btn;
            }
            if (btn) {
                showMask();
                $.ajax({
                    type: "POST",
                    url: "${ctx}/wupingfafang/zhihuan.do?keshi="  + keshi + "&fafangren=" + fafangren,
                    data:{"tiaomas":JSON.stringify(tiaoma)},
                    error: function (request) {
                        layer.alert("网络故障，请稍后再试!");
                    },
                    success: function (data) {
                        $("#mask").hide();
                        if (data.status == "true") {
                            layer.alert(data.msg, function () {
                                window.location.href = "${ctx}/wupingfafang/kucunxinxi.do";
                            });
                        } else {
                            layer.msg(data.msg);
                        }
                    }
                });
            }

        });

        $(".packMx").live("dblclick", function () {
            $(this).addClass("xuanzhong").siblings().removeClass("xuanzhong");
            var packId = $(this).attr("data");
            //找儿子的典例
            var name = $(this).find("td:eq(2)").text();
            layer.open({
                type: 2,
                title: name + '包明细',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['800px', '520px'],
                content: '${ctx}/wutiaoma/findQixieListPeibao.do?id=' + packId + '&name=' + name
            });
        })

        $("#checkriqi").click(function () {
            $.ajax({
                type: "POST",
                url: "${ctx}/wupingfafang/checkriqi.do",
                error: function (request) {
                    layer.alert("网络故障，请稍后再试!");
                },
                success: function (data) {
                    if (data.status == "false") {
                        layer.alert(data.msg, function () {
                            window.location.href = "${ctx}/wupingfafang/kucunxinxi.do";
                        });
                    } else {
                        var list = data.guoqibaoList;
                        alert(list.length);
                        layer.msg(data.msg);
                        /* layer.open({
                         type: 2,
                         title: '录入手术包条码',
                         maxmin: true,
                         moveOut:true,
                         shadeClose: true, //点击遮罩关闭层
                         area : ['750px' , '520px'],
                         content: "
                        ${ctx}/wupingfafang/wupinshenqing.do?shenqingliushui="+liushui+"&shuliang="+num+"&fafangren="+fafangren,
                         }); */
                    }
                }
            });
        });
    });

    //接受条码枪的录入
    function callbackPackData(data) {
        var baoArr = data;//扫码传入
        var baoTmArr = [];//页面显示
        var wybao = [];
        var btnArr = [];
        $('input[name="key"]').each(function () {
            baoTmArr.push($(this).val());
        });
        var bao = null;
        var baoTm = null;
        for (var i = 0; i < baoArr.length; i++) {
            btnArr = [];
            bao = baoArr[i];
            for (var j = 0; j < baoTmArr.length; j++) {
                baoTm = baoTmArr[j];
                if (bao == baoTm) {
                    $('input[name="key"]').each(function () {
                        if ($(this).val() == bao) {
                            $(this).prop('checked', true);
                        }
                    });

                } else {
                    btnArr.push(baoTm);
                }
            }
            if (btnArr.length == baoTmArr.length) {
                wybao.push(bao);
            }
        }
        if (wybao.length != 0) {
            alert("不能进行操作的包:" + wybao);
        }
    }

    function getSelRecord() {
        var chk_value = [];
        $('input[name="key"]:checked').each(function () {
            chk_value.push($(this).val());
        });
        return chk_value;
    }
    function getSelRecordTwo() {
        var chk_value = [];
        $('input[name="keytwo"]:checked').each(function () {
            chk_value.push($(this).val());
        });
        return chk_value;
    }

    function getshuju() {
        var liushuimingxi = [];
        $('input[name="key"]:checked').each(function () {
            var flag = $(this).attr("shuju");
            liushuimingxi.push($(this).attr("shuju"));

        });
        return liushuimingxi;
    }

    function getParameter(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    function isNullOrEmpty(strVal) {
        strVal = strVal.replace(/(^\s*)|(\s*$)/g, "");
        if (strVal == '' || strVal == null || strVal == undefined) {
            return true;
        } else {
            return false;
        }
    }

    document.onkeydown = function (event) {
        var e = event || window.event || arguments.callee.caller.arguments[0];
        var oPlay0 = document.getElementById("audio");
        var oPlay1 = document.getElementById("audio1");
        if (e && e.keyCode == 27) { // 按 Esc
            //要做的事情
        }
        if (e && e.keyCode == 113) { // 按 F2
            //要做的事情
        }
        if (e && e.keyCode == 13) { // enter 键
            var packageTiaomaFocus = $("#packageTiaoma").is(":focus");
            if (packageTiaomaFocus == true) {
                var lan = $("#packageTiaoma").val();
                if (lan != null) {
                    var flag = false;
                    console.log(flag)
                    $('input[name="key"]').each(function () {
                        if ($(this).val() == lan) {
                            flag = true;
                            // 清空配包的属性
                            var that = this;
                            $(that).prop('checked', true);
                            oPlay0.play();
                        }
                    });

                }
                $("#packageTiaoma").val('');
            } else if (renFocus == true) {
                $(".query-btn").click();
                oPlay1.play();
            }
            //要做的事情
        }
    };

    //iframe界面的 回调函数
    <%--$(document).ready(function(){--%>
    <%--layer.open({--%>
    <%--type: 2,--%>
    <%--title: '发放扫码',--%>
    <%--maxmin: true,--%>
    <%--shadeClose: false, //点击遮罩关闭层--%>
    <%--area : ['800px' , '520px'],--%>
    <%--content: '${ctx}/page/wupinfafang/fafang_barcode.jsp'--%>
    <%--});--%>
    <%----%>
    <%--});--%>
    //重新执行点击出详细信息的方法
    function callbackData(liushuiId) {
        console.log(liushuiId);
        $.ajax({
            type: "POST",
            url: "${ctx}/shoushumuban/ssbDetailList.do?id=" + liushuiId,
            error: function (request) {
                layer.alert("网络故障，请稍后再试!");
            },
            success: function (data) {
                if (data.status == "true") {
                    console.log(data);
                    var dataList = data.mxList;
                    var str = '';
                    var baoId = data.packageId;
                    $("#detail tbody").empty();
                    for (var i = 0; i < dataList.length; i++) {
                        str += "<tr><td><input type='checkbox' name=\"key\" value=\"" + dataList[i].productId + "\"/></td><td>" + dataList[i].productId + "</td><td>" + dataList[i].productName + "</td><td>" + dataList[i].num + "</td></tr>";
                    }
                    $("#detail tbody").append(str);
                } else {
                    layer.msg(data.msg);
                }
            }
        });
    }
</script>
</body>
</html>